package com.itheima.controller;

import com.itheima.domain.Address;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 王加鑫
 * @Date 2021/07/26 20:42
 * @Since JDK 1.8
 */
@Controller
public class AjaxController {

    @RequestMapping("/ajaxReturnJson01")
    @ResponseBody
    public Address ajaxReturnJson01(){
        System.out.println("com.itheima.controller return json pojo...");
        Address address = new Address();
        address.setProvince("安徽");
        address.setCity("安庆");
        return address;
    }

    @RequestMapping("/ajaxReturnJson02")
    @ResponseBody
    public List<Address> ajaxReturnJson02(){
        List<Address> addressList = new ArrayList<>();
        Address address = new Address();
        address.setProvince("安徽");
        address.setCity("安庆");
        Address address2 = new Address();
        address2.setProvince("广州");
        address2.setCity("广东");
        addressList.add(address);
        addressList.add(address2);
        return addressList;
    }

    @RequestMapping("/ajaxReturnJson03")
    @ResponseBody
    public Address ajaxReturnJson03(@RequestBody Address address){
        address.setProvince(address.getProvince());
        address.setCity(address.getCity());
        return address;
    }

}
